home *** CD-ROM | disk | FTP | other *** search
- Path: news.ov.com!news
- From: glenn@ov.com (Fletcher.Glenn@ov.com)
- Newsgroups: comp.lang.c
- Subject: Re: What is wrong with this loop?
- Date: 19 Apr 1996 15:16:58 GMT
- Organization: OpenVision
- Message-ID: <4l8apa$kv8@spanky.pls.ov.com>
- References: <4l86la$1t9@uwm.edu>
- Reply-To: glenn@ov.com
- NNTP-Posting-Host: foghorn.pls.ov.com
-
- In article 1t9@uwm.edu, mardavuy@alpha2.csd.uwm.edu (Mario David Uy) writes:
- >#include <stdio.h>
- >int main(void)
- >{
- > int dia;
- >
- > char cd;
- >
- > ...
- >
- > scanf("%c", &cd);
- > while (cd != 'm' || cd ! 'f' || cd != 'o')
- > {
- > printf("Re-enter m, f, or o.\n");
- > scanf(%c", &cd);
- > }
- > ...
- >}
- >
- >It works fine, except that it gives me the printf() twice.
- >
- >David
- >mardavuy@csd.uwm.edu
- >--
- >-------------------------------------------------------------------------------
- >|| ||Is it gonna be hide or seek, ||
- >|| Mario David Uy || is it gonna be win or lose? ||
- >|| mardavuy@csd.uwm.edu ||Is it gonna be pride that keeps||
-
-
- My bet is that you have forgotten that the '\n' in your input is
- also a character. Try changing your while statement from:
-
- while (cd != 'm' || cd ! 'f' || cd != 'o')
-
- to: while(cd != 'm' || cd != 'f' || cd != 'o' || cd != '\n')
-
- Fletcher.Glenn@ov.com
-
-
-
-